package com.xxq.controller;

import com.xxq.model.UserInfo;
import com.xxq.service.UserInfoService;
import com.xxq.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/user")
@Api(value = "用户接口管理", tags = {"用户接口管理"})
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/getUserInfos")
    @ApiOperation(value = "根据Id查询用户信息", notes = "根据Id查询用户信息")
    public ResponseVo getUserInfoById(Integer id) {
        UserInfo userInfo = userInfoService.getUserInfoById(id);
        return ResponseVo.success(userInfo);
    }

    @GetMapping("/setRedisKey")
    @ApiOperation(value = "设置redis Key-Value", notes = "设置redis Key-Value")
    public ResponseVo setRedisKey(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        return ResponseVo.success();
    }

    @GetMapping("/getRedisKey")
    @ApiOperation(value = "获取redis Value", notes = "获取redis Value")
    public ResponseVo getRedisKey(String key) {
        String value = redisTemplate.opsForValue().get(key);
        return ResponseVo.success(value);
    }
}
